package liangtWorkSpace.Observer.HeadFiestObsver.display;

import liangtWorkSpace.Observer.HeadFiestObsver.subject.Subject;

/**
 * @ClassName CurrentConditionsDisplay
 * @Description : 布告栏实时信息更新
 * @Author : LiangT
 * @Date : 2020/6/17 20:04
 */
public class CurrentConditionsDisplay implements Observer,DisplayElement{
    /* 压强 */
    private float pressure;
    /* 湿度 */
    private float humidity;
    /* 温度 */
    private float temperature;
    /* 监控者父类 */
    private Subject weaterData;

    /**
     * 构造函数将自己注册到一个主题中
     * @param weaterData
     */
    public CurrentConditionsDisplay(Subject weaterData) {
        this.weaterData = weaterData;
        weaterData.registerObserver(this);
    }

    /**
     * 展示获取到的温度和湿度
     */
    @Override
    public void disPlay() {
        System.out.println("Current conditions:"+temperature
        + "F degrees and "+ humidity + "% humidity");
    }

    /**
     * 将自己注册到气象站中，并再获取到温度信息后更新自己布告栏里的相关信息
     * @param temp
     * @param humidity
     * @param pressure
     */
    @Override
    public void update(float temp, float humidity, float pressure) {
        this.temperature = temp;
        this.humidity = humidity;
        disPlay();
    }
}
